<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Summarize environmental and demographic indicators at each location and overall — doaggregate • EJAM</title><!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png"><link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png"><link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png"><link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png"><link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png"><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/font-awesome-6.4.2/css/all.min.css" rel="stylesheet"><link href="../deps/font-awesome-6.4.2/css/v4-shims.min.css" rel="stylesheet"><script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><meta property="og:title" content="Summarize environmental and demographic indicators at each location and overall — doaggregate"><meta name="description" content="Used by ejamit() and the shiny app to summarize blockgroups scores at each site and overall."><meta property="og:description" content="Used by ejamit() and the shiny app to summarize blockgroups scores at each site and overall."><meta property="og:image" content="https://usepa.github.io/EJAM/logo.svg"></head><body>
    <a href="#main" class="visually-hidden-focusable">Skip to contents</a>


    <nav class="navbar navbar-expand-lg fixed-top bg-light" data-bs-theme="light" aria-label="Site navigation"><div class="container">

    <a class="navbar-brand me-2" href="../index.html">EJAM</a>

    <small class="nav-text text-warning me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Released version">2.32.0</small>


    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div id="navbar" class="collapse navbar-collapse ms-3">
      <ul class="navbar-nav me-auto"><li class="active nav-item"><a class="nav-link" href="../reference/index.html">Reference</a></li>
<li class="nav-item dropdown">
  <button class="nav-link dropdown-toggle" type="button" id="dropdown-articles" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">Articles</button>
  <ul class="dropdown-menu" aria-labelledby="dropdown-articles"><li><hr class="dropdown-divider"></li>
    <li><h6 class="dropdown-header" data-toc-skip>Overview for EJAM Users</h6></li>
    <li><a class="dropdown-item" href="../articles/0_whatis.html">What is EJAM</a></li>
    <li><a class="dropdown-item" href="../articles/0_webapp.html">Using EJAM</a></li>
    <li><hr class="dropdown-divider"></li>
    <li><h6 class="dropdown-header" data-toc-skip>For analysts using R</h6></li>
    <li><a class="dropdown-item" href="../articles/1_installing.html">Installing the EJAM R package</a></li>
    <li><a class="dropdown-item" href="../articles/2_quickstart.html">Quick Start Guide</a></li>
    <li><a class="dropdown-item" href="../articles/3_analyzing.html">Basics of Using EJAM for Analysis in RStudio</a></li>
    <li><a class="dropdown-item" href="../articles/4_advanced.html">Advanced Features</a></li>
  </ul></li>
<li class="nav-item"><a class="nav-link" href="../news/index.html">Changelog</a></li>
      </ul><ul class="navbar-nav"><li class="nav-item"><form class="form-inline" role="search">
 <input class="form-control" type="search" name="search-input" id="search-input" autocomplete="off" aria-label="Search site" placeholder="Search for" data-search-index="../search.json"></form></li>
<li class="nav-item"><a class="external-link nav-link" href="https://github.com/USEPA/EJAM/" aria-label="GitHub"><span class="fa fab fa-github fa-lg"></span></a></li>
      </ul></div>


  </div>
</nav><div class="container template-reference-topic">
<div class="row">
  <main id="main" class="col-md-9"><div class="page-header">
      <img src="../logo.svg" class="logo" alt=""><h1>Summarize environmental and demographic indicators at each location and overall</h1>
      <small class="dont-index">Source: <a href="https://github.com/USEPA/EJAM/blob/HEAD/R/doaggregate.R" class="external-link"><code>R/doaggregate.R</code></a></small>
      <div class="d-none name"><code>doaggregate.Rd</code></div>
    </div>

    <div class="ref-description section level2">
    <p>Used by ejamit() and the shiny app to summarize blockgroups scores at each site and overall.</p>
    </div>

    <div class="section level2">
    <h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">doaggregate</span><span class="op">(</span></span>
<span>  <span class="va">sites2blocks</span>,</span>
<span>  sites2states_or_latlon <span class="op">=</span> <span class="cn">NA</span>,</span>
<span>  radius <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  countcols <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  wtdmeancols <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  calculatedcols <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  subgroups_type <span class="op">=</span> <span class="st">"nh"</span>,</span>
<span>  include_ejindexes <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>  calculate_ratios <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>  extra_demog <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>  need_proximityscore <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>  infer_sitepoints <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>  called_by_ejamit <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>  updateProgress <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  silentinteractive <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>  testing <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>  showdrinkingwater <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>  showpctowned <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>  <span class="va">...</span></span>
<span><span class="op">)</span></span></code></pre></div>
    </div>

    <div class="section level2">
    <h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>


<dl><dt id="arg-sites-blocks">sites2blocks<a class="anchor" aria-label="anchor" href="#arg-sites-blocks"></a></dt>
<dd><p>data.table of distances in miles between all sites (facilities) and
nearby Census block internal points, with columns ejam_uniq_id, blockid, distance,
created by getblocksnearby  function.
See <a href="testoutput_getblocksnearby_10pts_1miles.html">testoutput_getblocksnearby_10pts_1miles</a> dataset in package, as input to this function</p></dd>


<dt id="arg-sites-states-or-latlon">sites2states_or_latlon<a class="anchor" aria-label="anchor" href="#arg-sites-states-or-latlon"></a></dt>
<dd><p>data.table or just data.frame,
with columns ejam_uniq_id (each unique one in sites2blocks) and
ST (2-character State abbreviation) or lat and lon</p></dd>


<dt id="arg-radius">radius<a class="anchor" aria-label="anchor" href="#arg-radius"></a></dt>
<dd><p>Optional radius in miles to limit analysis to. By default this function uses
all the distances that were provided in the output of getblocksnearby(),
and reports radius estimated as rounded max of distance values in inputs to doaggregate.
But there may be cases where you want to run getblocksnearby() once for 10 miles, say,
on a very long list of sites (1,000 or more, say), and then get summary results for
1, 3, 5, and 10 miles without having to redo the getblocksnearby() part for each radius.
This lets you just run getblocksnearby() once for the largest radius, and then query those
results to get doaggregate() to summarize at any distance that is less than or equal to the
original radius analyzed by getblocksnearby().</p></dd>


<dt id="arg-countcols">countcols<a class="anchor" aria-label="anchor" href="#arg-countcols"></a></dt>
<dd><p>character vector of names of variables  to aggregate within a buffer
using a sum of counts, like, for example, the number of people for whom a
poverty ratio is known, the count of which is the exact denominator needed
to correctly calculate percent low income.</p></dd>


<dt id="arg-wtdmeancols">wtdmeancols<a class="anchor" aria-label="anchor" href="#arg-wtdmeancols"></a></dt>
<dd><p>character vector of names of variables to aggregate within a buffer
using a population weighted mean or other type of weighted mean.</p></dd>


<dt id="arg-calculatedcols">calculatedcols<a class="anchor" aria-label="anchor" href="#arg-calculatedcols"></a></dt>
<dd><p>character vector of names of variables to aggregate within a buffer
using formulas that have to be specified.</p></dd>


<dt id="arg-subgroups-type">subgroups_type<a class="anchor" aria-label="anchor" href="#arg-subgroups-type"></a></dt>
<dd><p>Optional (uses default). Set this to
"nh" for non-hispanic race subgroups as in Non-Hispanic White Alone, nhwa and others in names_d_subgroups_nh;
"alone" for EJScreen v2.2 style race subgroups as in    White Alone, wa and others in names_d_subgroups_alone;
"both" for both versions. Possibly another option is "original" or "default" but work in progress.</p></dd>


<dt id="arg-include-ejindexes">include_ejindexes<a class="anchor" aria-label="anchor" href="#arg-include-ejindexes"></a></dt>
<dd><p>whether to calculate EJ Indexes and return that information</p></dd>


<dt id="arg-calculate-ratios">calculate_ratios<a class="anchor" aria-label="anchor" href="#arg-calculate-ratios"></a></dt>
<dd><p>whether to calculate and return ratio of each indicator to its US and State overall mean</p></dd>


<dt id="arg-extra-demog">extra_demog<a class="anchor" aria-label="anchor" href="#arg-extra-demog"></a></dt>
<dd><p>if should include more indicators from EJScreen v2.2 report,
on language, more age groups, gender, percent with disability, poverty, etc.</p></dd>


<dt id="arg-need-proximityscore">need_proximityscore<a class="anchor" aria-label="anchor" href="#arg-need-proximityscore"></a></dt>
<dd><p>whether to calculate proximity scores</p></dd>


<dt id="arg-infer-sitepoints">infer_sitepoints<a class="anchor" aria-label="anchor" href="#arg-infer-sitepoints"></a></dt>
<dd><p>set to TRUE to try to infer the lat,lon of each site around which the blocks in sites2blocks were found.
lat,lon of each site will be approximated as average of nearby blocks, although a more accurate slower way would
be to use reported distance of each of 3 of the furthest block points and triangulate</p></dd>


<dt id="arg-called-by-ejamit">called_by_ejamit<a class="anchor" aria-label="anchor" href="#arg-called-by-ejamit"></a></dt>
<dd><p>Set to TRUE by ejamit() to suppress some outputs even if ejamit(silentinteractive=F)</p></dd>


<dt id="arg-updateprogress">updateProgress<a class="anchor" aria-label="anchor" href="#arg-updateprogress"></a></dt>
<dd><p>progress bar function used for shiny app</p></dd>


<dt id="arg-silentinteractive">silentinteractive<a class="anchor" aria-label="anchor" href="#arg-silentinteractive"></a></dt>
<dd><p>Set to TRUE to see results in RStudio console.
Set to FALSE to prevent long output showing in console in RStudio when in interactive mode</p></dd>


<dt id="arg-testing">testing<a class="anchor" aria-label="anchor" href="#arg-testing"></a></dt>
<dd><p>used while testing this function</p></dd>


<dt id="arg--">...<a class="anchor" aria-label="anchor" href="#arg--"></a></dt>
<dd><p>more to pass to another function? Not used currently.</p></dd>

</dl></div>
    <div class="section level2">
    <h2 id="value">Value<a class="anchor" aria-label="anchor" href="#value"></a></h2>
    <p>list with named elements:</p><ul><li><p><strong><code>results_overall</code></strong>   one row data.table, like results_bysite, but just one row with
aggregated results for all unique residents.</p></li>
<li><p><strong><code>results_bysite</code></strong>   results for individual sites (buffers) - a data.table of results,
one row per ejam_uniq_id, one column per indicator</p></li>
<li><p><strong>results_bybg_people</strong>  results for each block group, to allow for showing the distribution of each
indicator across everyone within each demographic group.</p></li>
<li><p><strong>longnames</strong>  descriptive long names for the indicators in the above outputs</p></li>
<li><p><strong>count_of_blocks_near_multiple_sites</strong>  additional detail</p></li>
</ul></div>
    <div class="section level2">
    <h2 id="details">Details<a class="anchor" aria-label="anchor" href="#details"></a></h2>
    <p><code><a href="getblocksnearby.html">getblocksnearby()</a></code> and doaggregate() are the two key functions that run <code><a href="ejamit.html">ejamit()</a></code>.
<code>doaggregate()</code> takes a set of sites like facilities and the
set of blocks that are near each,
combines those with indicator scores for block groups, and
aggregates the numbes within each place and across all overall.</p>
<p>For all examples, see <code><a href="getblocksnearbyviaQuadTree.html">getblocksnearbyviaQuadTree()</a></code></p>
<p><code>doaggregate()</code> is the code run after <code><a href="getblocksnearby.html">getblocksnearby()</a></code> (or a related function for
polygons or FIPS Census units) has identified which blocks are nearby.</p>
<p><code>doaggregate()</code> aggregates the blockgroup scores to create a summary of each indicator,
as a raw score and US percentile and State percentile,
in each buffer (i.e., near each facility):</p><ul><li><p><strong>SUMS OF COUNTS</strong>: for population count, or number of households or Hispanics, etc.</p></li>
<li><p><strong>POPULATION-WEIGHTED MEANS</strong>: for  Environmental indicators, but also any percentage indicator
for which the universe (denominator) is population count (rather than households, persons age 25up, etc.)</p>
<p><em><strong>EJ Indexes</strong>:</em> The pop wtd mean of EJ Index raw scores.</p></li>
<li><p><strong>CALCULATED BY FORMULA</strong>: Buffer or overall score calculated as weighted mean of percentages, where the weights are
the correct denominator like count of those for whom the poverty ratio is known.</p></li>
<li><p><strong>LOOKED UP</strong>: Aggregated scores are converted into percentile terms via lookup tables (US or State version).</p></li>
</ul><p>This function requires the following datasets:</p><ul><li><p><a href="blockwts.html">blockwts</a>: data.table with these columns: blockid , bgid, blockwt</p></li>
<li><p><a href="quaddata.html">quaddata</a> data.table used to create localtree, a quad tree index of block points
(and localtree that is created when package is loaded)</p></li>
<li><p><a href="blockgroupstats.html">blockgroupstats</a> - A data.table (such as EJScreen demographic and environmental data by blockgroup)</p></li>
</ul></div>
    <div class="section level2">
    <h2 id="identification-of-nearby-residents-methodology-"><strong>Identification of nearby residents – methodology:</strong><a class="anchor" aria-label="anchor" href="#identification-of-nearby-residents-methodology-"></a></h2>
    <p>EJAM uses the same approach as EJScreen does to identify the count and demographics of nearby residents,
so EJScreen technical documentation should be consulted on the approach,
at <a href="https://www.epa.gov/ejscreen/technical-information-about-ejscreen" class="external-link">EJScreen Technical Info</a>.uri target="_blank" rel="noreferrer noopener".
EJAM implements that approach using faster code and data formats, but it
still uses the same high-resolution approach as described in EJScreen documentation
and summarized below.</p>
<p>The identification of nearby residents is currently done in a way that includes all 2020 Census blocks whose
"internal point" (a lat/lon provided by the Census Bureau) is within the specified distance of the facility point.
This is taken from the EJScreen block weights file, but can also be independently calculated.</p>
<p>The summary or aggregation or "rollup" within the buffer is done by calculating the
population-weighted average block group score among all the people residing in the buffer.
The weighting is by population count for variables that are fractions of population,
but other denominators and weights (e.g., households count) are used as appropriate,
as explained in EJScreen technical documentation on the formulas, and
replicated by formulas used in EJAM functions such as doaggregate().</p>
<p>Since the blockgroup population counts are from American Community Survey (ACS) estimates,
but the block population counts are from a decennial census, the totals for a blockgroup differ.
The amount each partial blockgroup contributes to the buffer's overall score is based on
the estimated number of residents from that blockgroup who are in the buffer.
This is based on the fraction of the blockgroup population that is estimated to be in the buffer,
and that fraction is calculated as the fraction of the blockgroup's decennial census block population
that is in the census blocks inside the buffer.</p>
<p>A given block is considered entirely inside or entirely outside the buffer,
and those are used to more accurately estimate what fraction of a given block group's
population is inside the buffer. This is more accurate and faster than areal apportionment of block groups.
Census blocks are generally so small relative to typical buffers that this is very accurate -
it is least accurate if a very small buffer distance is specified
in an extremely low density rural area where a block can be geographically large.
Although it is rarely if ever a significant issue (for reasonable, useful buffer sizes),
an even more accurate approach in those cases might be either areal apportionment of blocks,
which is very slow and assumes residents are evenly spread out across the full block's area,
or else an approach that uses higher resolution estimates of residential locations than even
the Decennial census blocks can provide, such as a dasymetric map approach.</p>
    </div>
    <div class="section level2">
    <h2 id="see-also">See also<a class="anchor" aria-label="anchor" href="#see-also"></a></h2>
    <div class="dont-index"><p><a href="ejamit.html">ejamit</a>   <code><a href="getblocksnearby.html">getblocksnearby()</a></code></p></div>
    </div>

  </main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
    </nav></aside></div>


    <footer><div class="pkgdown-footer-left">
  <p>US EPA 2024</p>
</div>

<div class="pkgdown-footer-right">
  <p>EJAM Version 2.32.0</p>
</div>

    </footer></div>





  </body></html>

